# Maintainer: kpcyrd <kpcyrd[at]archlinux[dot]org>

pkgname=vultr-cli
pkgver=2.16.2
pkgrel=1
pkgdesc='Official command line tool for Vultr services'
url='https://github.com/vultr/vultr-cli'
arch=('loong64' 'x86_64')
license=('Apache')
makedepends=('go')
source=(https://github.com/vultr/${pkgname}/archive/v${pkgver}/${pkgname}-${pkgver}.tar.gz)
sha512sums=('de9c9f0ecf8c2980bb685a60428ad3f1d54c28ced1ca98faf6dcf7531990af6e5da897d8e57275858e4569280d87914c0cd9bdf53fe5fa083418b151a30ccad3')
b2sums=('f4d86335c836843c420b801fd1fa2b047569d8a7828ecaa206cff65a21674eb5b497f4838a7225a0f7e20b440754c1b1934233bb5ceadc36101fdfb2c8b6117a')

build() {
  cd ${pkgname}-${pkgver}
  go build \
    -trimpath \
    -buildmode=pie \
    -mod=readonly \
    -modcacherw \
    -ldflags "-linkmode external -extldflags \"${LDFLAGS}\"" \
    .
}

package() {
  cd ${pkgname}-${pkgver}
  install -Dm 755 vultr-cli -t "${pkgdir}/usr/bin"

  install -d "${pkgdir}/usr/share/bash-completion/completions" \
             "${pkgdir}/usr/share/zsh/site-functions" \
             "${pkgdir}/usr/share/fish/vendor_completions.d"

  # workaround, see https://github.com/vultr/vultr-cli/issues/92#issuecomment-877722219
  export VULTR_API_KEY=x
  ./vultr-cli completion bash > "${pkgdir}/usr/share/bash-completion/completions/vultr-cli"
  ./vultr-cli completion zsh > "${pkgdir}/usr/share/zsh/site-functions/_vultr-cli"
  ./vultr-cli completion fish > "${pkgdir}/usr/share/fish/vendor_completions.d/vultr-cli.fish"
}

# vim: ts=2 sw=2 et:
